#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2025/2/5 16:18
# @Author  : Fancy
# @FileName: base.py 数据库类型修改此文件即可
# @Software: PyCharm
# @runstate    ：
# clients/base.py
from abc import ABC, abstractmethod
from db_compare.config import DBConfig


class BaseClient(ABC):

    @classmethod
    def create (cls, config: DBConfig) -> 'BaseClient':
        """工厂方法动态创建客户端"""

        from db_compare.clients.mysql import MySQLClient
        from db_compare.clients.dm import DMClient
        from db_compare.clients.postgres import PGClient

        clients = {
            "mysql": MySQLClient,
            "postgresql": PGClient,
            "dm":DMClient
        }

        client_class = clients.get (config.db_type)
        if not client_class:
            raise ValueError (f"Unsupported database type: {config.db_type}")

        return client_class (config)
    @abstractmethod
    def get_conn(self):
        """获取数据库连接"""
        pass

    @abstractmethod
    def fetch_stream(self, table: str, batch_size: int = 1000):
        """流式获取数据"""
        pass
